{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 机器学习100天——第二天：简单线性回归\n",
    "## 第一步：数据预处理"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里导入我们需要的库，值得注意的是，这里比第一天多了一个matplotlib.pyplot,matplotlib是python上的一个2D绘图库,\n",
    "matplotlib下的模块pyplot是一个有命令样式的函数集合，\n",
    "matplotlib.pyplot是为我们对结果进行图像化作准备的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "导入相关数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "    Hours  Scores\n",
      "0     2.5      21\n",
      "1     5.1      47\n",
      "2     3.2      27\n",
      "3     8.5      75\n",
      "4     3.5      30\n",
      "5     1.5      20\n",
      "6     9.2      88\n",
      "7     5.5      60\n",
      "8     8.3      81\n",
      "9     2.7      25\n",
      "10    7.7      85\n",
      "11    5.9      62\n",
      "12    4.5      41\n",
      "13    3.3      42\n",
      "14    1.1      17\n",
      "15    8.9      95\n",
      "16    2.5      30\n",
      "17    1.9      24\n",
      "18    6.1      67\n",
      "19    7.4      69\n",
      "20    2.7      30\n",
      "21    4.8      54\n",
      "22    3.8      35\n",
      "23    6.9      76\n",
      "24    7.8      86\n"
     ]
    }
   ],
   "source": [
    "dataset = pd.read_csv('../datasets/studentscores.csv')\n",
    "print(dataset)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里我们需要使用pandas的iloc(区分于loc根据index来索引，iloc利用行号来索引)方法来对数据进行处理，第一个参数为行号，:表示全部行，第二个参数 ：1表示截到第1列(也就是取第0列)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "X: [[2.5]\n",
      " [5.1]\n",
      " [3.2]\n",
      " [8.5]\n",
      " [3.5]\n",
      " [1.5]\n",
      " [9.2]\n",
      " [5.5]\n",
      " [8.3]\n",
      " [2.7]\n",
      " [7.7]\n",
      " [5.9]\n",
      " [4.5]\n",
      " [3.3]\n",
      " [1.1]\n",
      " [8.9]\n",
      " [2.5]\n",
      " [1.9]\n",
      " [6.1]\n",
      " [7.4]\n",
      " [2.7]\n",
      " [4.8]\n",
      " [3.8]\n",
      " [6.9]\n",
      " [7.8]]\n",
      "Y: [21 47 27 75 30 20 88 60 81 25 85 62 41 42 17 95 30 24 67 69 30 54 35 76\n",
      " 86]\n"
     ]
    }
   ],
   "source": [
    "X = dataset.iloc[ : ,   : 1 ].values\n",
    "Y = dataset.iloc[ : , 1 ].values\n",
    "print(\"X:\",X)\n",
    "print(\"Y:\",Y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "导入sklearn库的cross_validation类来对数据进行训练集、测试集划分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "#拆分数据，0.25作为测试集\n",
    "X_train, X_test, Y_train, Y_test = train_test_split( X, Y, test_size = 1/4, random_state = 0) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 训练线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "#使用训练集对模型进行训练\n",
    "regressor = LinearRegression()\n",
    "regressor = regressor.fit(X_train, Y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 预测结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "Y_pred = regressor.predict(X_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 可视化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 训练集结果可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAGkNJREFUeJzt3XuMXOV5x/Hv41uwHZBd24Cx8S7kQkkphGghUCpCcaBJg7ikrZRkQwiBOhdETEuaOKVSSlWTkgutkqiWXNvULUsuNaZcRBIMwWlQwNWaO5jWCfgO2GAMMUvq2vv0j/dMdmZ2Zmdm58ycd878PpK1e86OZ59g5+d3n/NezN0REZHONyHrAkREJB0KdBGRnFCgi4jkhAJdRCQnFOgiIjmhQBcRyQkFuohITijQRURyQoEuIpITk9r5zWbPnu29vb3t/JYiIh1v48aNL7v7nFqva2ug9/b2Mjg42M5vKSLS8cxsaz2vU8tFRCQnFOgiIjmhQBcRyQkFuohITijQRURyQoEuItKIgQHo7YUJE8LHgYGsK/qNtk5bFBHpaAMDsGgRDA2F661bwzVAf392dSU0QhcRqdd1142EecHQULgfAQW6iEi9tm1r7H6bKdBFROq1YEFD99vdblegi4jUa+lSmDat9N60aeF+mUK7fetWcB9pt7cy1BXoIiL16u+H5cuhpwfMwsflyys+EM2i3W7u3rp3L9PX1+fanEtEusGECWFkXs4Mhocbey8z2+jufTW/Z2NvKyIiY3njDZg+vXKYQ/U2fBoU6CIiKfn2t+Gtbx1ptRx2WOnXq7TbU6NAFxFp0osvhlbK5z8frq+4IozQV6yoq92eGq0UFRFpwMBAeLC5bVton7zznbBu3cjXt2+H+fPD5/397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iNgZszsAmC3u2/Mso4qznL39wAfBK5KWntZmwS8B1jm7qcCbwBLsi0pSNo/FwL/nnUtAGY2E7gIOA44BphuZh/PsiZ33wTcCKwjtFseBw5mVY8CvQFJn/o2YMDd12ZdT7Hkx/T1wAcyLuUs4MKkX/094FwzuyXbkgJ335V83A3cTuh7Zm0HsKPoJ6s1hICPwQeBR9z9pawLSbwfeN7d97j7/wFrgd/LuCbcfaW7v8fdzya0ijPpn4MCvW7JA8iVwCZ3vynregDMbI6ZzUg+n0r4C/9sljW5+5fdfb679xJ+XP+Ju2c6igIws+nJw2ySlsb5hB+XM+XuLwLbzeyE5NZCILMH7WU+SiTtlsQ24Awzm5b8/3Eh4VlWpszsyOTjAuDDZPjfLMozRc3su8A5wGwz2wF8xd1XZlsVZwGXAk8mPWuAv3L3ezKsaS6wOpmJMAH4gbtHM00wMkcBt4ccYBJwq7v/KNuSfuNqYCBpcTwHXJ5xPST94POAT2ddS4G7bzCzNcAjhLbGo0SwOhO4zcxmAf8HXOXur2ZVSJTTFkVEpHFquYiI5IQCXUQkJxToIiI5oUAXEckJBbqISE4o0EVEckKBLiKSEwp0EZGc+H8Ad1Wk1CaNtgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#散点图\n",
    "plt.scatter(X_train , Y_train, color = 'red')\n",
    "#线图\n",
    "plt.plot(X_train , regressor.predict(X_train), 'bo-')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 测试集结果可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2Z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V+17AW4B/gXoTLqQInHgaTNbaWZNSRdToI8C7cBd0ZLYnWZ2RNJFFcGXgfuSLiJXCvQezGwk8AvganfflXQ9+XL3g+4+BZgATDWz/5N0Tfkws88D2919ZdK1FNHZ7n4GcD7wDTM7N+mCCjAYOAO4zd1PB/YA1yRbUmGiZaOLgIeSriVXCvRuovXmXwDN7v5I0vUUQ/TX32eBv0y4lHydDVwUrTvfD0wzs58nW1Jh3H1r9LgdWARMTbaigrwOvN7tb4APEwK+mp0PrHL3tqQLyZUCPRJ9kLgAWOfuNyddTyHMrM7MRkdfHw58Dngl2ary4+7XuvsEd68n/DX4GXe/LOGy8mZmR0QfuhMtTZwHrEm2qvy5+x+BLWZ2YjQ1Hai6Cwl6uJQqXG6BKrmnaJmcDfxf4KVo7RngOnd/IsGa8jUOWBh9Un8Y8KC7V/3lfikxFlgU+gcGA/e6+1PJllSwfwCao6WK14CvJlxP3sxsBDAD+HrSteRDly2KiKSEllxERFJCgS4ikhIKdBGRlFCgi4ikhAJdRCQlFOgiIimhQBcRSQkFuohISvwvXoX2unAFLdIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#散点图\n",
    "plt.scatter(X_test , Y_test, color = 'red')\n",
    "#线图\n",
    "plt.plot(X_test ,Y_pred, 'bo-')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
